#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.common.bean.po;

import ${package}.common.bean.vo.CodeApiVo;
import ${package}.common.bean.vo.CodeVo;
import ${package}.common.emum.CommonStatusEnum;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import com.google.common.base.MoreObjects;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.io.Serializable;

/**
 * Description: Code po
 *
 * @author wenxiaopeng
 * @date 2020/07/24 14:00
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Code implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long id;
	/**
	 * 代码
	 */
	private String code;
	/**
	 * 代码含义
	 */
	private String value;
	/**
	 * 在业务层面上的代码
	 */
	private String aka;
	/**
	 * 上级代码id
	 */
	@JSONField(serializeUsing = ToStringSerializer.class)
	private Long upperCodeId;
	/**
	 * 代码类型id
	 */
	@JSONField(serializeUsing = ToStringSerializer.class)
	private Long codeTypeId;
	/**
	 * 代码顺序
	 */
	private Integer codeOrder;

	/**
	 * 代码状态
	 * @see ${package}.common.emum.CommonStatusEnum
	 **/
	private Integer status;

	/** 转VO */
	public CodeVo asVo() {
		return new CodeVo(id, code, aka, value, upperCodeId, codeTypeId, codeOrder, status,null);
	}

	/** 转ApiVo，美化部分字段 */
	public CodeApiVo asApiVo() {
		return CodeApiVo.builder()
				.id(id)
				.code(code)
				.value(value)
				.order(codeOrder)
				.upperCodeId(upperCodeId)
				.enable(CommonStatusEnum.STATUS_VALID.getCode().equals(status))
				.aka(aka).build();
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}

		if (o == null || getClass() != o.getClass()) {
			return false;
		}

		Code code1 = (Code) o;

		return new EqualsBuilder()
				.append(id, code1.id)
				.append(code, code1.code)
				.append(value, code1.value)
				.append(upperCodeId, code1.upperCodeId)
				.append(codeTypeId, code1.codeTypeId)
				.append(status, code1.status)
				.isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37)
				.append(id)
				.append(code)
				.append(value)
				.append(upperCodeId)
				.append(codeTypeId)
				.append(status)
				.toHashCode();
	}

	@Override
	public String toString() {
		return MoreObjects.toStringHelper(this)
				.add("id", id)
				.add("code", code)
				.add("aka", aka)
				.add("value", value)
				.add("upperCodeId", upperCodeId)
				.add("codeTypeId", codeTypeId)
				.add("codeOrder", codeOrder)
				.add("status", status)
				.toString();
	}
}
